#! /usr/bin/python

import math
import time

limit = 4* 10**7
tt = time.time()
def isPrime(n):
    if n ==2 or n==3 or n==5 or n==7: return True
    if n==1 or n%2 == 0 or n%3 == 0: return False
    for i in range(5, int(math.sqrt(n))+1, 6):
        if n%i == 0 or n%(i+2) == 0: return False
    return True

phi = [i for i in range(limit)]
cfun = [0 for i in range(limit)]

primes = []
for i in range(2, len(phi)):
    if phi[i] == i:
	for j in range(i, len(phi), i):
	    phi[j] = phi[j]/i*(i-1)


for i in range(limit):
    cfun[i] = cfun[phi[i]] + 1

print cfun[0:10]

ss = 0
for i in range(10**6+1, limit, 2):
    if cfun[i] == 25 and isPrime(i):
	ss += i

print ss

print time.time() - tt
